
//处理登录逻辑业务
import 'package:flutter/cupertino.dart';
import 'package:mvvmdemo/common/appglabaldata.dart';
import 'package:mvvmdemo/model/syj_model.dart';
import 'package:mvvmdemo/model/user_model.dart';
import 'package:mvvmdemo/service/parameter_interface.dart';

class LoginViewModel {
  static  LoginViewModel? _loginViewModel;
  static LoginViewModel? getLoginViewModel(){
    _loginViewModel ??= LoginViewModel();
    return _loginViewModel;
   }
  getSysPara() async {
    String erpCode = "004";
    String mkt = "80001";
    String syjh = "0001";
    String ipAddress = "172.17.8.216";
    String version = "21111701";
    var result = await ParameterInterface.getNetService()!.posStartupCertify(
      erpCode: erpCode,
      mkt:mkt,
      syjh:syjh,
      ipAdress:ipAddress,
      version:version
    );
    if(null!=result&&result['returncode']=='0'){
      AppGlabalData.syjModel = SyjModel.fromJson(result);
      print(AppGlabalData.syjModel!.data!.syjmain!.mkt);
    }
  }

  login(BuildContext context) async {
    String cardno = "";
    String gh = "7005";
    String passwd = "1";
    String mkt = "80001";
    String syjh = "0001";
    String erpCode = "004";
    String loginFlag = "N";
    String workRound = "0";
    String empLoginType = "0";
    String entId = "0";
    String netType = "2";
    var result = await ParameterInterface.getNetService()!.posLogin(
      cardno:cardno,
      gh:gh,
      passwd:passwd,
      mkt:mkt,
      syjh:syjh,
      erpCode:erpCode,
      loginFlag:loginFlag,
      workRound:workRound,
      empLoginType:empLoginType,
      entId:entId,
      netType:netType,
    );
    if(null!=result&&result['returncode']=='0'){
      AppGlabalData.userDataModel = UserModel.fromJson(result);
      Navigator.pushReplacementNamed(context,"/salepage");
    }
  }
}